clear all
global dir "C:\Users\mrueda\Documents\Emory\Papers\Networks_persistance\do_files\do_files_APSA21\post_JOP\Replication_BJPS\"
		
		use "$dir\Data\council_cand_level_persist_rep.dta",clear


	global balance_ind women sanc_before pol_exp_d elec_exp_d 
	global balance_fin all total_income donations_total
	global balance_donors family cont_donor_101 cont_donor_102 contraloria above_lim    
	global balance_all $balance_ind $balance_fin $balance_donors


	
	texdoc close 
	cap erase "$dir/Tables/TableH3.tex"
	texdoc init "$dir/Tables/TableH3.tex", force

	tex \begin{table}[tbph]
	tex \caption{Candidate characteristics around the electoral victory cutoff}\label{tab:smooth_win_council}
	tex \begin{center}
	tex \scalebox{.8}{%
	tex {\normalsize
	tex \begin{tabular}{l c c c c c c c c}
	tex \toprule[1.5pt]
	tex \multicolumn{1}{c}{} & Mean &  Std. Dev. & Victory & CI 95\% &
	tex Obs. & Band. Obs.  & Bandwith & p-value \\
	tex & (1) & (2) & (3) & (4) & (5) & (6) & (7) & (8) \\
	tex \hline
	tex \addlinespace
	tex \multicolumn{6}{l}{\textit{Panel A:Candidates' characteristics}}\\
	tex \addlinespace
	
	foreach x in $balance_all{	
	
		*Summary statistics for the mean
		sum `x'
			local mean_`x' : di %5.3f r(mean)
			local sd_`x' : di %5.3f r(sd) 
		
		*Regressions
		rdrobust `x' rv2, all vce(cluster muni_code) 
		
		*Local's for the table
		local bw_`x' : di %9.2f `e(h_l)'
		local ser_`x' = round(`e(se_tau_rb)',0.001)
		local Neff_`x' = `e(N_h_l)'+`e(N_h_r)'
		local N_`x' = `e(N)'
		local poly_`x' = `e(p)'
		local beta1_`x' : di %5.3f `e(tau_cl)'
		local beta2_`x' : di %5.3f `e(tau_cl)'

		*Confidence intervals
			local ser1_`x' : di %5.3f `e(ci_l_rb)'
			local ser2_`x' : di %5.3f `e(ci_r_rb)'
			
/* HERE*/	local em1_`x' = (`beta1_`x''/`mean_`x'')*100 
			local em1_`x' : di %5.2f `em1_`x''
			
		*P-values
		local pval1_`x' : di %5.3f `e(pv_cl)'
		local pval2_`x' : di %5.3f `e(pv_rb)'
		
		
	}	


	
	*Table continue
	tex \ Women & `mean_women' & `sd_women' & `beta2_women' & [`ser1_women',`ser2_women'] & `N_women' & `Neff_women' & `bw_women' & `pval2_women' \\
	tex \ Sanctioned & `mean_sanc_before' & `sd_sanc_before' & `beta2_sanc_before' & [`ser1_sanc_before',`ser2_sanc_before'] & `N_sanc_before' & `Neff_sanc_before' & `bw_sanc_before' & `pval2_sanc_before' \\
	tex \ Political experience & `mean_pol_exp_d' & `sd_pol_exp_d' & `beta2_pol_exp_d' & [`ser1_pol_exp_d',`ser2_pol_exp_d'] & `N_pol_exp_d' & `Neff_pol_exp_d' & `bw_pol_exp_d' & `pval2_pol_exp_d' \\
	tex \ Held office before & `mean_elec_exp_d' & `sd_elec_exp_d' & `beta2_elec_exp_d' & [`ser1_elec_exp_d',`ser2_elec_exp_d'] & `N_elec_exp_d' & `Neff_elec_exp_d' & `bw_elec_exp_d' & `pval2_elec_exp_d' \\
	tex \\
	
	tex \multicolumn{6}{l}{\textit{Panel B: General funding covariates}}\\
	tex \addlinespace	
	tex \ Donors (all) & `mean_all' & `sd_all' & `beta2_all' & [`ser1_all',`ser2_all'] & `N_all' & `Neff_all' & `bw_all' & `pval2_all' \\
	tex \ Campaign revenue & `mean_total_income' & `sd_total_income' & `beta2_total_income' & [`ser1_total_income',`ser2_total_income'] & `N_total_income' & `Neff_total_income' & `bw_total_income' & `pval2_total_income' \\
	tex \ Donations /Revenue & `mean_donations_total' & `sd_donations_total' & `beta2_donations_total' & [`ser1_donations_total',`ser2_donations_total'] & `N_donations_total' & `Neff_donations_total' & `bw_donations_total' & `pval2_donations_total' \\

	tex \\
	tex \multicolumn{6}{l}{\textit{Panel C: Donors characteristics}}\\
	tex \addlinespace	
	tex \ Family & `mean_family' & `sd_family' & `beta2_family' & [`ser1_family',`ser2_family'] & `N_family' & `Neff_family' & `bw_family' & `pval2_family' \\
	tex \ Avg. Donation (non-family) & `mean_cont_donor_102' & `sd_cont_donor_102' & `beta2_cont_donor_102' & [`ser1_cont_donor_102',`ser2_cont_donor_102'] & `N_cont_donor_102' & `Neff_cont_donor_102' & `bw_cont_donor_102' & `pval2_cont_donor_102' \\
	tex \ Avg. Donation (family) & `mean_cont_donor_101' & `sd_cont_donor_101' & `beta2_cont_donor_101' & [`ser1_cont_donor_101',`ser2_cont_donor_101'] & `N_cont_donor_101' & `Neff_cont_donor_101' & `bw_cont_donor_101' & `pval2_cont_donor_101' \\
	tex \ Comptroller sanction & `mean_contraloria' & `sd_contraloria' & `beta2_contraloria' & [`ser1_contraloria',`ser2_contraloria'] & `N_contraloria' & `Neff_contraloria' & `bw_contraloria' & `pval2_contraloria' \\
	tex \ Above limit & `mean_above_lim' & `sd_above_lim' & `beta2_above_lim' & [`ser1_above_lim',`ser2_above_lim'] & `N_above_lim' & `Neff_above_lim' & `bw_above_lim' & `pval2_above_lim' \\

	
	tex \addlinespace
	tex \midrule[1 pt]
	tex \end{tabular}
	tex }}
	tex \parbox{160mm}{ \scriptsize{
	tex Columns 1 and 2 report the descriptive statistics. Column 3 reports local linear estimates of average treatment effects at the cutoff estimated with triangular kernel weights and optimal MSE bandwidth (reported in column 7). Columns 4 and 8 report 95\% robust confidence intervals and robust p-values computed following \citep{calonico_robust_2014}. Columns 5 and 6 report total observations and observations in optimal MSE bandwidth. Sanctioned indicates the candidate has been sanctioned by the Office of the Inspector General. Donors and Donations include the totals for non-family and family donors. Family is the fraction of donors who are family members of the candidate. Above limit is the fraction of donors contributing above the individual legal limit. 
	tex }
	tex }
	tex \end{center}
	tex \end{table}
	cap texdoc close
